package br.inatel.ec203.projeto.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

public class EditDeleteCancelButtonsPanel extends JPanel{

	private static final long serialVersionUID = 867551065611320703L;
	
	private EditDeleteCancelButtonsListener editDeleteCancelButtonsListener;
	
	private JButton editButton;
	private JButton deleteButton;
	private JButton cancelButton;
	
	public EditDeleteCancelButtonsPanel() {
		
		initialize();
	}

	private void initialize() {
		add(getEditButton());
		add(getDeleteButton());	
		add(getCancelButton());
	}

	private JButton getEditButton() {
		if (editButton == null) {
			editButton = new JButton();
			editButton.setText("Editar");
			editButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					editDeleteCancelButtonsListener.editPerformed();				
				}
			});
		}
		return editButton;
	}

	private JButton getDeleteButton() {
		if (deleteButton == null) {
			deleteButton = new JButton();
			deleteButton.setText("Deletar");
			deleteButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {					
					editDeleteCancelButtonsListener.deletePerformed();
				}
			});
		}
		return deleteButton;
	}

	public JButton getCancelButton() {
		if (cancelButton == null) {
			cancelButton = new JButton();
			cancelButton.setText("Cancelar");
			cancelButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					editDeleteCancelButtonsListener.cancelPerformed();					
				}
			});
		}
		return cancelButton;
	}
	
	public void addEditDeleteCancelButtonsListener(
			EditDeleteCancelButtonsListener editDeleteCancelButtonsListener) {
		this.editDeleteCancelButtonsListener = editDeleteCancelButtonsListener;
	}
}








